﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Fantacid303.ProcessAffinityControl.Manager.MainWindowViewModels;
using System.Threading;

namespace Fantacid303.ProcessAffinityControl.Manager
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		Mutex mutex;

		protected override void OnStartup(StartupEventArgs e)
		{
			base.OnStartup(e);

			this.mutex = new Mutex(true, "{BDF371B1-DE6D-4F16-B283-3EE929C1CDC7}");
			if (!this.mutex.WaitOne(0))
			{
				MessageBox.Show("The Process Affinity Control Manager is already running!", "Already Running", MessageBoxButton.OK, MessageBoxImage.Information);
				this.Shutdown();
				return;
			}

			var vm = new ConfigurationViewModel();
			var wnd = new TestWindow();
			wnd.DataContext = vm;
			wnd.Show();
		}

		protected override void OnExit(ExitEventArgs e)
		{
			base.OnExit(e);

			if (this.mutex != null)
				this.mutex.Dispose();
		}
	}
}
